<?php
require_once "../../PCO.php";
require_once DIR_CLASSES."client.class";
require_once DIR_FUNCTIONS."functions.php";

$nom_cli="";
$sir_cli="";
$res_cli="";
$num_cli="";
if($_GET[VAR_GET_CLI]!=""){
	$num_cli=$_GET[VAR_GET_CLI]; // recuperer le numero du client en GET.
	$client = new Client();
	$client->setNum($num_cli);
	$client->getAllByNum($num_cli); //recuperer les infos du client.
	$nom_cli=$client->getNom(); // nom du client
	$sir_cli=$client->getSiren(); // SIREN du client
	$res_cli=$client->getResp();  // Responsable du client.
	
}
else {
	echo "Erreur : numero client non trouve...";
}


?>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Vision globale Client THEMIS - client <?php echo $num_cli; ?></title>
	<link rel="stylesheet" type="text/css" href="<?=URL_CSS?>easyui.css">
	<link rel="stylesheet" type="text/css" href="<?=URL_CSS?>themisstyle.css">
	<link rel="stylesheet" type="text/css" href="<?=URL_CSS?>icon.css">
	<script type="text/javascript" src="<?=URL_JS?>jquery.js"></script>
	<script type="text/javascript" src="<?=URL_JS?>jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<?=URL_JS?>cookie.jquery.js"></script>	
    <script type="text/javascript" src="<?=URL_JS?>jquery.editinplace.js"></script>
	<script>
	$(document).ready(function(){
		$(".panel-body").css("background","#AFCBF3");
		$(".tabs").append("<span style='margin-left:5%'><select id='cli' ><option value='1'>Onglet 1</option><option value='2'>Onglet 2</option><option value='3'>Onglet 3</option></select>&nbsp;<input size='15' type='text' id='add' />&nbsp;<input type='button' value='MAJ titre' id='ajout' /></span>");
		
		var id="tabs";
		var cook="";
		$('.tabs-title').each(function(i){
		$(this).attr("id", i+1);
		});
		if($.cookie(id)==null){
			$("#1").html("Onglet 1");
			$("#2").html("Onglet 2");
			$("#3").html("Onglet 3");
			cook=$("#1").text()+"|"+$("#2").text()+"|"+$("#3").text();
			$.cookie(id,cook);
		}
		else {
			var col=$.cookie(id).split("|");
			$("#1").html(col[0]);
			$("#2").html(col[1]);
			$("#3").html(col[2]);
		}

		var width=document.body.clientWidth;
		$(window).bind('resize', function() {
			 if (document.body.clientWidth!=width)
			   {window.location.href = window.location.href;
			    width=document.body.clientWidth;
  			   }		 
			});	
		});
	</script>
	<script>
	$(document).ready(function(){
		$("#ajout").click(function(){
			var id="tabs";
			var cook="";
			var onglet=$("#cli").val();
			var texte=$('#add').val();
			if(texte !=""){
				if(onglet==1){
					$("#"+onglet).text(texte);
					cook=$("#"+onglet).text()+"|"+$("#2").text()+"|"+$("#3").text();
					$.cookie(id, cook);
				}				
				else if(onglet==2){
					$("#"+onglet).text(texte);
					cook=$("#1").text()+"|"+$("#"+onglet).text()+"|"+$("#3").text();
					$.cookie(id, cook);
				
				}				
				
				else if(onglet==3){
					$("#"+onglet).text(texte);
					cook=$("#1").text()+"|"+$("#2").text()+"|"+$("#"+onglet).text();
					$.cookie(id, cook);
				}
				else {
					alert("Erreur : vous avez tapé un titre qui existe dejà.")
				}
			}
			else {
				alert("Remplissez le champ texte svp");
			}
		})
	});
	</script>
	<script type="text/javascript">	
		$(document).ready(function(){
			$("#note").keyup(function(){
				$("#sauv").css("display", "inline");
				$("#annul").css("display", "inline");
			});
		});
    </script>	
	<script type="text/javascript">	
		$(document).ready(function(){
			var valu="<?php echo getNote($num_cli); ?>";
			if($.trim(valu)=="")
				valu="Inserer une note sur le client: <?php echo $num_cli; ?>";
			var reg=new RegExp("(,)", "g");
			 valu=valu.replace(reg, "\n");
			 $("#note").val(valu);
		});
    </script>		
	<script type="text/javascript">	
		$(document).ready(function(){
			$("#sauv").click(function(){
				var textar=$.trim($("#note").val());
				textar = textar.replace(/[@#$%\^&*=_+"'\/<>\\\|{}\[\]]/g,"");
				textar = textar.replace(/[\t ]+/g,' ');
				textar = textar.replace(/\n{1,}/g,'\n\n');
				textar = textar.split(/\n/);
				var dataString = "id="+<?php echo $num_cli;?>+"&value="+textar;
				// alert(dataString);
				$.ajax	({
					type: "POST",
					url: "../post-it/note.php",
					data: dataString,
					cache: false,
					success: function(html){
						if(textar=="")
							$("#note").val("Inserer une note sur le client: <?php echo $num_cli; ?>");
						$("#sauv").css("display", "none");
						$("#annul").css("display", "none");
					},
					error: function(xhr, status, errorThrown) {
							alert(xhr+ ' : error ajax - contactez DESI : status '+ status + ' && ' + errorThrown);
					}
				});
			})
			$("#annul").click(function(){
				var valu="<?php echo getNote($num_cli); ?>";
				if($.trim(valu)=="")
					valu="Inserer une note sur le client: <?php echo $num_cli; ?>";
				var reg=new RegExp("(,)", "g");
				valu=valu.replace(reg, "\n");
				$("#note").val(valu);
				$("#sauv").css("display", "none");
				$("#annul").css("display", "none");
			});
			
			
			$('#tt').tabs({  
				// http://www.jeasyui.com/documentation/index.php# pour voir la documentation
				// fit:true, 
				// onSelect:function(title){  
				// alert(title+' is selected');  
				// }  
				fit: true
			});  
			
			
		});
    </script>
</head>
<body>
	<table width="100%" height="100%">
		<tr width="100%" height="10%">
			<td align="left">
				<table  class='t_head_mini' width="100%">
					<tr>
						<td rowspan='2'>
							<img src="<?=URL_IMAGES?>logo.gif"  class='logo'>
						</td>
						<th>
							Client
						</th>
						<th>	
							SIREN
						</th>
						<th>	
							Responsable
						<th>
					</tr>
					<?php
					echo "<tr><td><span id='num_cli'>".$num_cli."</span>&nbsp;";
					echo $nom_cli;
					echo "<td>".$sir_cli;
					echo "<td>".$res_cli."</td></tr>";
					?>
				</table>
			</td>

			<td align="right">
				<FIELDSET style='width:45%;float:right;overflow:visible;'>
					<LEGEND align=top> Post-it:</LEGEND> 
					<textarea cols="68" rows='4'  id="note" style="background-color:#eedd82;"  >
					</textarea><br>
					<input type='button' value='Sauvegarder' id='sauv' style="display: none;"/>
					<input type='button' value='Annuler' id='annul' style="display: none;"/>
				</FIELDSET>
			</td>

		</tr>
		<tr width="100%" height="90%">
			<td colspan="2" valign="top" id="tdframe">
				<div id="tt" class="easyui-tabs" style='background:#AFCBF3;' width="100%" height="100%">
					<div title="" id="c1">
						<iframe scrolling="auto" frameborder="0"   src="./C1/igoogle_client.php?numCli=<?php echo $num_cli; ?>" width="100%" height="100%"></iframe>
					</div>
					<div title="" id="c2">
						<iframe scrolling="auto" frameborder="0"   src="./C2/igoogle_client.php?numCli=<?php echo $num_cli; ?>" style="width:100%;height:100%;"></iframe>
					</div>
					<div title="" id="c3">
						<iframe scrolling="auto" frameborder="0"  src="./C3/igoogle_client.php?numCli=<?php echo $num_cli; ?>" style="width:100%;height:100%;"></iframe>
					</div>
				</div>
			</td>
		</tr>
	</table>	
</body>
</html>